﻿using System;
using System.Collections.Generic;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;

namespace TestDxfDocument
{
    class CylindricalShank
    {   //f
        public static void Cylinder_StyleF_InsertC(Dictionary<string,Object> data) {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线
            
            double pi = Math.PI;
            //参数名称取自ISO 5609-2
            double d1 = Convert.ToDouble(data["d1"]);
            double l1 = Convert.ToDouble(data["l1"]);
            double l2 = Convert.ToDouble(data["l2"]);
            double f = Convert.ToDouble(data["f"]);
            double Dmin = Convert.ToDouble(data["dmin"]);
            double s = Convert.ToDouble(data["s"]);
            double insertAgl = Convert.ToDouble(data["insertagl"]) * pi / 180;
            double cutAgl = Convert.ToDouble(data["cutagl"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            double gamaf = Convert.ToDouble(data["gamaf"]) * pi / 180;
            string path = Convert.ToString(data["path"]);
            
            #region
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamf"] != null)
                    gamaf = Convert.ToDouble(data["gamf"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 6.4,0.4},
                { 11,0.4},
                { 16.5,0.8},
                { 22,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1-15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是到刀尖圆弧的距离，f是k点距离中心线的长度，k点位置参考5609-2
            Vector2 k1 = new Vector2(c1.Y + f - repsilon, c1.Y - l1);
            Vector2 kc = fun.Polar(k1, pi / 2, repsilon);
            Vector2 k2 = fun.Polar(kc, pi / 2 - insertAgl, repsilon);
            Vector2 k2p = fun.Polar(k2, -insertAgl, 1);
            Vector2 i4 = fun.Inters(k1, new Vector2(k1.X + 1, k1.Y), k2, k2p);
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2,Vector2.Angle(i2,i1),3), i2, fun.Polar(i2,Vector2.Angle(i2,i3),3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓
            double insertOffset = s * Math.Tan(an);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf,insertContour, 0.1, contour);
            //shank
            Vector2 c8 = fun.Inters(c10, c9, i4, i1);
            Vector2 c7 = new Vector2(i3.X - 2, i3.Y);
            Vector2 c6 = new Vector2(c5.X, c7.Y + 2);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(insertContour.Vertexes[2].Position, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, insertContour.Vertexes[7].Position);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf,c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 1) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            dxf.AddEntity(Pus.SectionSymbol(new Vector2((i3.X + i4.X) / 2, i3.Y - 0.5), new Vector2((i3.X + i4.X) / 2, i1.Y + 0.5),"A",7,1,textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(i4, c11), offset , -90,dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(i4, new Vector2(c1.X,i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i1, i2), offset * 0.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl *180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 3, i4.Y - 3));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dim_repsilon.SetDimensionLinePosition(new Vector2(i4.X + 1, i4.Y - 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            if(an== 11 * pi / 180) { 
                double anv = an;
                Vector2 a1 = new Vector2(i4.X + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.X, a1.Y + l2 * Math.Sin(insertAgl));
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3) , a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y+s*Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutPoints = { a1,a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint}, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline});
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) {}
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 7 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i4.X + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.X, a1.Y + l2 * Math.Sin(insertAgl));
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) { }
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 0 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i4.X + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.X, a1.Y + l2 * Math.Sin(insertAgl));
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) { }
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin/2+0.5), new Vector2(cs.X, cs.Y - Dmin/2-0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf,x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1,x2,x3,x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s,x1,x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X-Dmin/2,cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //t1,t2
            Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //X
            dxf.AddEntity( Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X",new Vector2(i3.X-1,i3.Y-offset*2-5-3),textHeigth,0));
            //X-X
            dxf.AddEntity(new Text("X", new Vector2(cs.X, cs.Y + offset * 1.5), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin),x1), offset * 1.6, 180,dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5*pi, d1/2), cs), offset * 2, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1/2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1,x4)*180/pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi+ "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void Cylinder_StyleF_InsertT(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleF_InsertT.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-2
            double d1 = 10;
            double l1 = 100;
            double l2 = 11.0;
            double f = 7;
            double Dmin = 13;
            double s = 2.38;
            double insertAgl = 60 * pi / 180;
            double cutAgl = 90 * pi / 180;
            double an = 11 * pi / 180;
            double gamaf = 10 * pi / 180;
            
            #region
            try
            {
                if (data["gamf"] != null)
                    gamaf = Convert.ToDouble(data["gamf"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]);
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 6.4,0.4},
                { 11,0.4},
                { 16.5,0.8},
                { 22,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是到刀尖圆弧的距离，f是k点距离中心线的长度，k点位置参考5609-2
            Vector2 k1 = new Vector2(c1.X + f - repsilon, c1.Y - l1);
            Vector2 kc = fun.Polar(k1, pi / 2, repsilon);
            Vector2 k2 = fun.Polar(kc, pi / 2 - insertAgl, repsilon);
            Vector2 k2p = fun.Polar(k2, -insertAgl, 1);
            Vector2 i1 = fun.Inters(k1, new Vector2(k1.X + 1, k1.Y), k2, k2p);
            Vector2[] insertContourPoints = Pus.ToVertical(i1,pi/2, Pus.TrianglePoints(i1, l2, false, cutAgl));
            Vector2 i2 = insertContourPoints[1];
            Vector2 i3 = insertContourPoints[2];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓
            double insertOffset = s * Math.Tan(11*pi/180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii1 = buttomInsert[0];
            Vector2 ii2 = buttomInsert[1];
            Vector2 ii3 = buttomInsert[2];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 c8 = new Vector2(ii1.X, c9.Y - 1);
            Vector2 u1;
            Arc iarc1 = Pus.GetArcFromPline(insertContour, 1);
            //与ii1共垂直x轴线的某一点
            Vector2 ii1p = new Vector2(ii1.X, ii1.Y + 1);
            List<Vector2> upoints = Pus.LineXArc(iarc1, ii1p, ii1);
            if (upoints == null || upoints.Count == 0)
                u1 = fun.Inters(i1, i2, ii1p, ii1);
            else if (upoints.Count == 1)
                u1 = upoints[0];
            else
                u1 = upoints[1];
            Vector2 u2;
            Arc iarc3 = Pus.GetArcFromPline(insertContour, 3);
            List<Vector2> upoints2 = Pus.LineXArc(iarc3, ii1, ii3);
            if (upoints2 == null|| upoints2.Count == 0)//先判断null再判断0才不会报错
                u2 = fun.Inters(ii1, ii3, i2, i3);
            else
                u2 = upoints2[0];
            Vector2 c7 = new Vector2(u2.X - 1, u2.Y);
            Vector2 c6 = fun.Inters(c7, fun.Polar(c7, 135 * pi / 180, 1), c4, c5);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1,c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, u2);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 1) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb1 = new Vector2((i3.X + i1.X) / 2 + 1, i1.Y - 0.5);
            Vector2 scsb2 = new Vector2((i3.X + i1.X) / 2 + 1, i2.Y - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(i1, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(new Vector2(kc.X+repsilon,kc.Y), new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5*
offset, Vector2.Angle(i1,i2)*180/pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i1, i3), new Line(i1, new Vector2(i1.X, i1.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i1.X - 3, i1.Y - 3));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dim_repsilon.SetDimensionLinePosition(new Vector2(i1.X + 1, i1.Y - 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            if (an == 11 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i1.X + offset * 3, i1.Y);
                double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i1, i3).Y;
                Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                dis = fun.Inters(scsb1, scsb2, ii1, ii2).Y - fun.Inters(scsb1, scsb2, ii1, ii3).Y;
                Vector2 a6 = new Vector2(a2.X - s, a5.Y + dis);
                Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) { }
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 7 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i1.X + offset * 3, i1.Y);
                double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i1, i3).Y;
                Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                dis = fun.Inters(scsb1, scsb2, ii1, ii2).Y - fun.Inters(scsb1, scsb2, ii1, ii3).Y;
                Vector2 a6 = new Vector2(a2.X - s, a5.Y + dis);
                Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) { }
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 0 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i1.X + offset * 3, i1.Y);
                double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i1, i3).Y;
                Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                dis = fun.Inters(scsb1, scsb2, ii1, ii2).Y - fun.Inters(scsb1, scsb2, ii1, ii3).Y;
                Vector2 a6 = new Vector2(a2.X - s, a5.Y + dis);
                Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_P;
                if (an == 11 * pi / 180)
                    inclination_P = 6;
                else if (an == 7 * pi / 180)
                    inclination_P = 0;
                else
                    inclination_P = -6;
                //double inclination_N = -6;
                //double inclination_C = 0;
                Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
                //中心线
                Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
                HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
                HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(P)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(C)";
                else
                    text = "αn=0°(N)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
                dimensionStyle2.ArrowSize = 0.1;
                dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionStyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                    dim_inclination_P.UserText = inclination_P + "°";
                    dxf.AddEntity(dim_inclination_P);
                }
                catch (Exception) { }
                Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
                dxf.AddEntity(ptext);
            }
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //t1,t2
            //Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            //Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            //Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X-X
            dxf.AddEntity(new Text("X", new Vector2(cs.X, cs.Y + offset * 1.5), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 1.6, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //k
        public static void Cylinder_StyleK_InsertS(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleK_InsertS.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-2
            double d1 = 16;
            double l1 = 150;
            double l2 = 9.52;
            double f = 11;
            double Dmin = 20;
            double s = 3.18;
            double a = 2.2;
            double insertAgl = 90 * pi / 180;
            double cutAgl = 75 * pi / 180;
            double an = 0 * pi / 180;
            #region
            try
            {
                if (data["lfa"] != null)
                    a = Convert.ToDouble(data["lfa"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 9.52,0.8},
                { 12.7,0.8},
                { 15.88,1.2},
                { 19.05,1.2},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是K点的位置尺寸，K点与i4点的关系参考文件StyleK_insertS.SLDPRT
            Vector2 k = new Vector2(c1.X + f, c1.Y - l1);
            //r-r(1-cos75)/sin75
            Vector2 i4 = fun.Polar(k, pi / 2 - cutAgl, repsilon - repsilon * (1 - Math.Cos(cutAgl)) / Math.Sin(cutAgl));
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓
            double insertOffset = s * Math.Tan(an * pi / 180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii4 = buttomInsert[0];
            Vector2 ii1 = buttomInsert[1];
            Vector2 ii2 = buttomInsert[2];
            Vector2 ii3 = buttomInsert[3];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 c8 = fun.Inters(i4, i1, c9, c10);
            Vector2 u1 = insertContour.Vertexes[2].Position;
            Vector2 u2;
            Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
            List<Vector2> upoints2 = Pus.LineXArc(iarc4, ii1, ii3);
            if (upoints2 == null || upoints2.Count == 0)//先判断null再判断0才不会报错
                u2 = fun.Inters(ii4, ii3, i2, i3);
            else
                u2 = upoints2[0];
            Vector2 c7 = new Vector2(u2.X - d1 / 4, u2.Y);
            Vector2 c6 = fun.Inters(c7, fun.Polar(c7, 135 * pi / 180, 1), c4, c5);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, u2);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 3) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb2 = new Vector2((i2.X + i1.X) / 2, (i1.Y + i2.Y) / 2 + 0.5);
            Vector2 scsb1 = new Vector2((i3.X + i4.X) / 2, (i3.Y + i4.Y) / 2 - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(k, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5 * offset, Vector2.Angle(i1, i2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y - 2));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            Vector3 cen = Pus.GetArcFromPline(insertContour, 1).Center;
            dim_repsilon.SetDimensionLinePosition(new Vector2(cen.X -1 ,cen.Y + 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            Dictionary<double, double> an_or = new Dictionary<double, double>()//后角与前角的对应关系
            {
                { 11 * pi / 180 ,6 },
                { 0 * pi / 180 ,-6 },
                { 7 * pi / 180 ,0 },
            };
            Vector2 a1 = new Vector2(i4.X + offset * 4, i4.Y);
            double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i4, i3).Y;
            Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
            Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
            Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(an));
            Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(an));
            Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(an));
            Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
            double inclination_P = an_or[an];
            Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
            //中心线
            Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
            //样条曲线
            Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
            dxf.AddEntity(spline);
            LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
            fun.PolyFill(dxf, pcontour1, 0.1, contour);
            LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
            pcut.IsClosed = true;
            fun.PolyFill(dxf, pcut, 0.1, contour);
            Pus.HatchThePolyline(dxf, pcut, -40, 2);
            //填充1
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
            HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
            HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
            boundary.Add(pcpath);
            boundary.Add(hpath2);
            Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
            hatch1.Pattern.Angle = 45;
            hatch1.Pattern.Scale = 4;
            dxf.AddEntity(hatch1);
            string text;
            if (an == 11 * pi / 180)
                text = "αn=11°(P)";
            else if (an == 7 * pi / 180)
                text = "αn=7°(C)";
            else
                text = "αn=0°(N)";
            Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
            dxf.AddEntity(text1);
            Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
            DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
            dimensionStyle2.ArrowSize = 0.1;
            dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
            dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
            dimensionStyle2.TextHeight = 0.3;
            try
            {
                Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                dim_inclination_P.UserText = inclination_P + "°";
                dxf.AddEntity(dim_inclination_P);
            }
            catch (Exception) { }
            Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
            dxf.AddEntity(ptext);
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            double gamaf = 10 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //t1,t2
            Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X视图文字
            dxf.AddEntity(new Text("X", new Vector2(cD.X, cD.Y + c_D.Radius + 2), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //u
        public static void Cylinder_StyleU_InsertD(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleU_InsertD.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-5
            double d1 = 12;
            double l1 = 125;
            double l2 = 7.75;
            double f = 9;
            double Dmin = 16;
            double s = 2.38;
            double a = 2.2;
            double insertAgl = 55 * pi / 180;
            double cutAgl = 93 * pi / 180;
            double an = 0 * pi / 180;
            #region
            try
            {
                if (data["lfa"] != null)
                    a = Convert.ToDouble(data["lfa"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 7.75,0.4},
                { 11.1,0.8},
                { 11.6,0.8},
                { 13.8,0.8},
                { 15.5,0.8},
                { 16.6,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是K点的位置尺寸，K点与i4点的关系参考文件StyleU_insertD.SLDPRT
            Vector2 k = new Vector2(c1.X + f, c1.Y - l1);
            //r/Tan(55/2)-r/Tan((180-93)/2)
            Vector2 i4 = fun.Polar(k, pi / 2 - cutAgl, repsilon / Math.Tan(insertAgl / 2) - repsilon / Math.Tan((pi - cutAgl) / 2));
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓,标准5609-5中只有后角为7与0的情况，此处都按后角为7度处理
            double insertOffset = s * Math.Tan(7 * pi / 180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii4 = buttomInsert[0];
            Vector2 ii1 = buttomInsert[1];
            Vector2 ii2 = buttomInsert[2];
            Vector2 ii3 = buttomInsert[3];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 u1;
            Arc iarc1 = Pus.GetArcFromPline(insertContour, 1);
            iarc1.StartAngle = 2 * pi;
            List<Vector2> upoints1 = Pus.LineXArc(iarc1, ii4, new Vector2(ii4.X, ii4.Y + 1));
            if (upoints1 == null || upoints1.Count == 0)
                u1 = fun.Inters(ii4, new Vector2(ii4.X, ii4.Y + 1), i4, i1);
            else if (upoints1.Count == 1)
                u1 = upoints1[0];
            else
                u1 = upoints1[1];
            Vector2 c8 = fun.Inters(c9, fun.Polar(c9, -pi / 4, 1), u1, fun.Polar(u1, pi / 2, 1));
            Vector2 c7;
            Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
            List<Vector2> c7s = Pus.LineXArc(iarc4, ii4, ii3);
            if (c7s == null || c7s.Count == 0)
                c7 = fun.Inters(ii4, ii3, i2, i3);
            else
                c7 = c7s[0];
            Vector2 c6 = fun.Inters(ii4, ii3, c4, c5);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 3) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb2 = new Vector2((i2.X + i1.X) / 2, (i1.Y + i2.Y) / 2 + 0.5);
            Vector2 scsb1 = new Vector2((i3.X + i4.X) / 2, (i3.Y + i4.Y) / 2 - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(k, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5 * offset, Vector2.Angle(i1, i2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y - 2));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            Vector3 cen = Pus.GetArcFromPline(insertContour, 1).Center;
            dim_repsilon.SetDimensionLinePosition(new Vector2(cen.X - 1, cen.Y + 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            Dictionary<double, double> an_or = new Dictionary<double, double>()//后角与前角的对应关系
            {
                { 11 * pi / 180 ,6 },
                { 0 * pi / 180 ,-6 },
                { 7 * pi / 180 ,0 },
            };
            Vector2 a1 = new Vector2(i4.X + offset * 4, i4.Y);
            double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i4, i3).Y;
            Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
            Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
            Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(an));
            Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(an));
            Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(an));
            Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
            double inclination_P = an_or[an];
            Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
            //中心线
            Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
            //样条曲线
            Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
            dxf.AddEntity(spline);
            LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
            fun.PolyFill(dxf, pcontour1, 0.1, contour);
            LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
            pcut.IsClosed = true;
            fun.PolyFill(dxf, pcut, 0.1, contour);
            Pus.HatchThePolyline(dxf, pcut, -40, 2);
            //填充1
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
            HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
            HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
            boundary.Add(pcpath);
            boundary.Add(hpath2);
            Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
            hatch1.Pattern.Angle = 45;
            hatch1.Pattern.Scale = 4;
            dxf.AddEntity(hatch1);
            string text;
            if (an == 11 * pi / 180)
                text = "αn=11°(P)";
            else if (an == 7 * pi / 180)
                text = "αn=7°(C)";
            else
                text = "αn=0°(N)";
            Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
            dxf.AddEntity(text1);
            Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
            DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
            dimensionStyle2.ArrowSize = 0.1;
            dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
            dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
            dimensionStyle2.TextHeight = 0.3;
            try
            {
                Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                dim_inclination_P.UserText = inclination_P + "°";
                dxf.AddEntity(dim_inclination_P);
            }
            catch (Exception) { }
            Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
            dxf.AddEntity(ptext);
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            double gamaf = 10 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X视图文字
            dxf.AddEntity(new Text("X", new Vector2(cD.X, cD.Y + c_D.Radius + 2), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void Cylinder_StyleU_InsertV(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleU_InsertV.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-5
            double d1 = 16;
            double l1 = 150;
            double l2 = 11.1;
            double f = 11;
            double Dmin = 20;
            double s = 2.38;
            double insertAgl = 35 * pi / 180;
            double cutAgl = 93 * pi / 180;
            double an = 0 * pi / 180;
            #region
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 7.75,0.4},
                { 11.1,0.8},
                { 11.6,0.8},
                { 13.8,0.8},
                { 15.5,0.8},
                { 16.6,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是K点的位置尺寸，K点与i4点的关系参考文件StyleU_insertD.SLDPRT
            Vector2 k = new Vector2(c1.X + f, c1.Y - l1);
            //r/tan(55/2)-r/tan((180-93)/2)
            Vector2 i4 = fun.Polar(k, pi / 2 - cutAgl, repsilon / Math.Tan(insertAgl / 2) - repsilon / Math.Tan((pi - cutAgl) / 2));
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓,标准5609-5中只有后角为7与0的情况，此处都按后角为7度处理
            double insertOffset = s * Math.Tan(7 * pi / 180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii4 = buttomInsert[0];
            Vector2 ii1 = buttomInsert[1];
            Vector2 ii2 = buttomInsert[2];
            Vector2 ii3 = buttomInsert[3];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 u1 = fun.Inters(new Vector2(ii4.X - 2, ii4.Y), new Vector2(ii4.X - 2, ii4.Y + 1), i4, i1);
            Vector2 c8 = fun.Inters(c9, fun.Polar(c9, -pi / 4, 1), u1, fun.Polar(u1, pi / 2, 1));
            Vector2 c7;
            Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
            List<Vector2> c7s = Pus.LineXArc(iarc4, ii4, ii3);
            if (c7s == null || c7s.Count == 0)
                c7 = fun.Inters(ii4, ii3, i2, i3);
            else
                c7 = c7s[0];
            Vector2 c6 = fun.Inters(ii4, ii3, c4, c5);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 3) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb2 = new Vector2((i2.X + i1.X) / 2, (i1.Y + i2.Y) / 2 + 0.5);
            Vector2 scsb1 = new Vector2((i3.X + i4.X) / 2, (i3.Y + i4.Y) / 2 - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(k, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5 * offset, Vector2.Angle(i1, i2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y - 2));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            Vector3 cen = Pus.GetArcFromPline(insertContour, 1).Center;
            dim_repsilon.SetDimensionLinePosition(new Vector2(cen.X - 1, cen.Y + 0.7));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            Dictionary<double, double> an_or = new Dictionary<double, double>()//后角与前角的对应关系
            {
                { 11 * pi / 180 ,6 },
                { 0 * pi / 180 ,-6 },
                { 7 * pi / 180 ,0 },
            };
            Vector2 a1 = new Vector2(i4.X + offset * 4, i4.Y);
            double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i4, i3).Y;
            Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
            Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
            Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(an));
            Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(an));
            Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(an));
            Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
            double inclination_P = an_or[an];
            Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
            //中心线
            Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
            //样条曲线
            Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
            dxf.AddEntity(spline);
            LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
            fun.PolyFill(dxf, pcontour1, 0.1, contour);
            LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
            pcut.IsClosed = true;
            fun.PolyFill(dxf, pcut, 0.1, contour);
            Pus.HatchThePolyline(dxf, pcut, -40, 2);
            //填充1
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
            HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
            HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
            boundary.Add(pcpath);
            boundary.Add(hpath2);
            Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
            hatch1.Pattern.Angle = 45;
            hatch1.Pattern.Scale = 4;
            dxf.AddEntity(hatch1);
            string text;
            if (an == 11 * pi / 180)
                text = "αn=11°(P)";
            else if (an == 7 * pi / 180)
                text = "αn=7°(C)";
            else
                text = "αn=0°(N)";
            Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
            dxf.AddEntity(text1);
            Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
            DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
            dimensionStyle2.ArrowSize = 0.1;
            dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
            dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
            dimensionStyle2.TextHeight = 0.3;
            try
            {
                Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                dim_inclination_P.UserText = inclination_P + "°";
                dxf.AddEntity(dim_inclination_P);
            }
            catch (Exception) { }
            Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
            dxf.AddEntity(ptext);
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 4, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            double gamaf = 10 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X视图文字
            dxf.AddEntity(new Text("X", new Vector2(cD.X, cD.Y + c_D.Radius + 2), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //q
        public static void Cylinder_StyleQ_InsertD(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleQ_InsertD.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-5
            double d1 = 12;
            double l1 = 125;
            double l2 = 7.75;
            double f = 9;
            double Dmin = 16;
            double s = 2.38;
            double insertAgl = 55 * pi / 180;
            double cutAgl = 107.5 * pi / 180;
            double an = 0 * pi / 180;
            #region
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 7.75,0.4},
                { 11.1,0.8},
                { 11.6,0.8},
                { 13.8,0.8},
                { 15.5,0.8},
                { 16.6,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c6 = fun.Polar(c5, -pi / 2, 8);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是K点的位置尺寸，K点与i4点的关系参考文件StyleU_insertD.SLDPRT
            Vector2 k = new Vector2(c1.X + f, c1.Y - l1);
            //r/tan(55/2)-r/tan((180-93)/2)
            Vector2 i4 = fun.Polar(k, pi / 2 - cutAgl, repsilon / Math.Tan(insertAgl / 2) - repsilon / Math.Tan((pi - cutAgl) / 2));
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓,标准5609-5中只有后角为7与0的情况，此处都按后角为7度处理
            double insertOffset = s * Math.Tan(7 * pi / 180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii4 = buttomInsert[0];
            Vector2 ii1 = buttomInsert[1];
            Vector2 ii2 = buttomInsert[2];
            Vector2 ii3 = buttomInsert[3];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 u1 = fun.Inters(new Vector2(ii4.X - 0.5, ii4.Y), new Vector2(ii4.X - 0.5, ii4.Y + 1), i4, i1);
            Vector2 c8 = fun.Polar(c9, -pi / 4, 2);
            Vector2 u2;
            Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
            List<Vector2> upoints2 = Pus.LineXArc(iarc4, ii3, ii4);
            if (upoints2 == null || upoints2.Count == 0)
                u2 = fun.Inters(ii3, ii4, i2, i3);
            else
                u2 = upoints2[0];
            Vector2 c7 = fun.Inters(c6, fun.Polar(c6, -pi / 4, 1), ii4, ii3);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, u2);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 3) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb2 = new Vector2((i2.X + i1.X) / 2, (i1.Y + i2.Y) / 2 + 0.5);
            Vector2 scsb1 = new Vector2((i3.X + i4.X) / 2, (i3.Y + i4.Y) / 2 - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(k, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5 * offset, Vector2.Angle(i1, i2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y - 2));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            Vector3 cen = Pus.GetArcFromPline(insertContour, 1).Center;
            dim_repsilon.SetDimensionLinePosition(new Vector2(cen.X - 1, cen.Y + 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            Dictionary<double, double> an_or = new Dictionary<double, double>()//后角与前角的对应关系
            {
                { 11 * pi / 180 ,6 },
                { 0 * pi / 180 ,-6 },
                { 7 * pi / 180 ,0 },
            };
            Vector2 a1 = new Vector2(i4.X + offset * 4, i4.Y);
            double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i4, i3).Y;
            Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
            Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
            Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(an));
            Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(an));
            Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(an));
            Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
            double inclination_P = an_or[an];
            Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
            //中心线
            Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
            //样条曲线
            Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
            dxf.AddEntity(spline);
            LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
            fun.PolyFill(dxf, pcontour1, 0.1, contour);
            LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
            pcut.IsClosed = true;
            fun.PolyFill(dxf, pcut, 0.1, contour);
            Pus.HatchThePolyline(dxf, pcut, -40, 2);
            //填充1
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
            HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
            HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
            boundary.Add(pcpath);
            boundary.Add(hpath2);
            Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
            hatch1.Pattern.Angle = 45;
            hatch1.Pattern.Scale = 4;
            dxf.AddEntity(hatch1);
            string text;
            if (an == 11 * pi / 180)
                text = "αn=11°(P)";
            else if (an == 7 * pi / 180)
                text = "αn=7°(C)";
            else
                text = "αn=0°(N)";
            Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
            dxf.AddEntity(text1);
            Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
            DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
            dimensionStyle2.ArrowSize = 0.1;
            dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
            dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
            dimensionStyle2.TextHeight = 0.3;
            try
            {
                Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                dim_inclination_P.UserText = inclination_P + "°";
                dxf.AddEntity(dim_inclination_P);
            }
            catch (Exception) { }
            Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
            dxf.AddEntity(ptext);
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            double gamaf = 10 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //t1,t2
            Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X视图文字
            dxf.AddEntity(new Text("X", new Vector2(cD.X, cD.Y + c_D.Radius + 2), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void Cylinder_StyleQ_InsertV(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "D:\\PPPPPPPPPPPPPPPPP\\dxf\\CylindricalShank\\Cylinder_StyleQ_InsertV.dxf";//Convert.ToString(data["path"]);
            double pi = Math.PI;
            //参数名称取自ISO 5609-5
            double d1 = 16;
            double l1 = 150;
            double l2 = 11.1;
            double f = 11;
            double Dmin = 20;
            double s = 2.38;
            double insertAgl = 35 * pi / 180;
            double cutAgl = 107.5 * pi / 180;
            double an = 0 * pi / 180;
            #region
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertAgl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutAgl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    Dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 7.75,0.4},
                { 11.1,0.8},
                { 11.6,0.8},
                { 13.8,0.8},
                { 15.5,0.8},
                { 16.6,0.8},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = l1 - 15;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c3 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c11 = new Vector2(c1.X + d1 / 2 - chamfer, c3.Y);
            Vector2 c4 = new Vector2(c3.X - chamfer, c3.Y - chamfer);
            Vector2 c10 = new Vector2(c11.X + chamfer, c4.Y);
            Vector2 c5 = new Vector2(c4.X, c3.Y - dtl);
            Vector2 c6 = fun.Polar(c5, -pi / 2, 8);
            Vector2 c9 = new Vector2(c10.X, c5.Y);
            //f,l1是K点的位置尺寸，K点与i4点的关系参考文件StyleU_insertD.SLDPRT
            Vector2 k = new Vector2(c1.X + f, c1.Y - l1);
            //r/tan(55/2)-r/tan((180-93)/2)
            Vector2 i4 = fun.Polar(k, pi / 2 - cutAgl, repsilon / Math.Tan(insertAgl / 2) - repsilon / Math.Tan((pi - cutAgl) / 2));
            Vector2[] insertContourPoints = Pus.DiamondPointsV(i4, l2, insertAgl, false, cutAgl);
            Vector2 i1 = insertContourPoints[1];
            Vector2 i2 = insertContourPoints[2];
            Vector2 i3 = insertContourPoints[3];
            LwPolyline littleAngle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleAngle, 0.1, contour);
            //insert底部轮廓,标准5609-5中只有后角为7与0的情况，此处都按后角为7度处理
            double insertOffset = s * Math.Tan(7 * pi / 180);
            Vector2[] buttomInsert = Pus.OffsetPoints(insertOffset, insertContourPoints);
            Vector2 ii4 = buttomInsert[0];
            Vector2 ii1 = buttomInsert[1];
            Vector2 ii2 = buttomInsert[2];
            Vector2 ii3 = buttomInsert[3];
            //fun.PolyFill(dxf, Pus.AddPointsToLwPolyLine(buttomInsert), 0.1, contour);
            //为四个角倒圆
            LwPolyline insertContour = Pus.AddPointsToLwPolyLine(insertContourPoints);
            insertContour.IsClosed = true;
            Pus.AglToArc(insertContour, repsilon);
            fun.PolyFill(dxf, insertContour, 0.1, contour);
            //shank
            Vector2 u1 = fun.Inters(new Vector2(ii4.X - 2, ii4.Y), new Vector2(ii4.X - 2, ii4.Y + 1), i4, i1);
            Vector2 c8 = fun.Inters(c9, fun.Polar(c9, -pi / 4, 1), u1, fun.Polar(u1, pi / 2, 1));
            Vector2 u2;
            Arc iarc4 = Pus.GetArcFromPline(insertContour, 4);
            List<Vector2> upoints2 = Pus.LineXArc(iarc4, ii3, ii4);
            if (upoints2 == null || upoints2.Count == 0)
                u2 = fun.Inters(ii3, ii4, i2, i3);
            else
                u2 = upoints2[0];
            Vector2 c7 = fun.Inters(c6, fun.Polar(c6, -pi / 4, 1), ii4, ii3);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(u1, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, u2);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 3) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double textH = 2.5;
            Vector2 scsb2 = new Vector2((i2.X + i1.X) / 2, (i1.Y + i2.Y) / 2 + 0.5);
            Vector2 scsb1 = new Vector2((i3.X + i4.X) / 2, (i3.Y + i4.Y) / 2 - 0.5);
            dxf.AddEntity(Pus.SectionSymbol(scsb1, scsb2, "A", 7, 1, textH));
            //标注
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(k, c11), offset, -90, dimensionStyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(k, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i2, i1), -0.5 * offset, Vector2.Angle(i1, i2) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionStyle);
            dim_d1.UserText = "Φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutAgl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionStyle);
            dim_cutAgl.UserText = cutAgl * 180 / pi + "°";
            dim_cutAgl.SetDimensionLinePosition(new Vector2(i4.X - 2, i4.Y - 2));
            dxf.AddEntity(dim_cutAgl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertContour, 1, dimensionStyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            Vector3 cen = Pus.GetArcFromPline(insertContour, 1).Center;
            dim_repsilon.SetDimensionLinePosition(new Vector2(cen.X - 1, cen.Y + 0.7));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            Dictionary<double, double> an_or = new Dictionary<double, double>()//后角与前角的对应关系
            {
                { 11 * pi / 180 ,6 },
                { 0 * pi / 180 ,-6 },
                { 7 * pi / 180 ,0 },
            };
            Vector2 a1 = new Vector2(i4.X + offset * 4, i4.Y);
            double dis = fun.Inters(scsb1, scsb2, i1, i2).Y - fun.Inters(scsb1, scsb2, i4, i3).Y;
            Vector2 a2 = new Vector2(a1.X, a1.Y + dis);
            Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
            Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(an));
            Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(an));
            Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(an));
            Vector2[] absolutPoints = { a1, a1, a2, a3, a4, a5, a6 };
            double inclination_P = an_or[an];
            Vector2[] p = Pus.ToVertical(absolutPoints[0], inclination_P * pi / 180, absolutPoints);
            //中心线
            Vector2 cendPoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendPoint }, 0.15, centre, Linetype.Center);
            //样条曲线
            Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
            dxf.AddEntity(spline);
            LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
            fun.PolyFill(dxf, pcontour1, 0.1, contour);
            LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
            pcut.IsClosed = true;
            fun.PolyFill(dxf, pcut, 0.1, contour);
            Pus.HatchThePolyline(dxf, pcut, -40, 2);
            //填充1
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>();
            HatchBoundaryPath pcpath = new HatchBoundaryPath(pcontour1.Explode());
            HatchBoundaryPath hpath2 = new HatchBoundaryPath(new List<EntityObject> { spline });
            boundary.Add(pcpath);
            boundary.Add(hpath2);
            Hatch hatch1 = new Hatch(HatchPattern.Line, boundary, true);
            hatch1.Pattern.Angle = 45;
            hatch1.Pattern.Scale = 4;
            dxf.AddEntity(hatch1);
            string text;
            if (an == 11 * pi / 180)
                text = "αn=11°(P)";
            else if (an == 7 * pi / 180)
                text = "αn=7°(C)";
            else
                text = "αn=0°(N)";
            Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
            dxf.AddEntity(text1);
            Line pCentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
            DimensionStyle dimensionStyle2 = fun.CreateDimStyle();
            dimensionStyle2.ArrowSize = 0.1;
            dimensionStyle2.DimArrow1 = DimensionArrowhead.Dot;
            dimensionStyle2.DimArrow2 = DimensionArrowhead.Dot;
            dimensionStyle2.TextHeight = 0.3;
            try
            {
                Angular2LineDimension dim_inclination_P = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new Line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionStyle);
                dim_inclination_P.UserText = inclination_P + "°";
                dxf.AddEntity(dim_inclination_P);
            }
            catch (Exception) { }
            Text ptext = new Text("A-A", new Vector2(cendPoint.X - 4, cendPoint.Y + 1), textH, 0);
            dxf.AddEntity(ptext);
            //X视图
            Vector2 cs = new Vector2(c6.X - offset * 4, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + Dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - Dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            double gamaf = 10 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new Line(xx1, x4));
            double cs_startAgl = Vector2.Angle(cs, xx1);
            Arc sArc = new Arc(cs, d1 / 2, cs_startAgl * 180 / pi, 270);
            sArc.Layer = contour;
            sArc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sArc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cD
            Vector2 cD = new Vector2(x1.X - Dmin / 2, cs.Y);
            //中心线
            Line vcline_cD = new Line(new Vector2(cD.X, cD.Y + 3), new Vector2(cD.X, cD.Y - 3));
            vcline_cD.Layer = centre;
            vcline_cD.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cD);
            //构造线（圆）
            Circle c_D = new Circle(cD, Vector2.Distance(x1, cD));
            c_D.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_D);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endAgl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endAgl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textHeigth = 2.5;
            //t1,t2
            Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //X
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("X", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textHeigth, 0));
            //X视图文字
            dxf.AddEntity(new Text("X", new Vector2(cD.X, cD.Y + c_D.Radius + 2), textHeigth, 0));
            //X标注
            LinearDimension dim_Dmin = new LinearDimension(new Line(fun.Polar(x1, pi, Dmin), x1), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim_Dmin, Dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionStyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionStyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //l
        public static void Cylinder_Stylel_InsertC(Dictionary<string, object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //1,轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //4,中心线

            string path = "d:\\ppppppppppppppppp\\dxf\\cylindricalshank\\cylinder_stylel_insertc.dxf";//convert.tostring(data["path"]);
            double pi = Math.PI;
            //参数名称取自iso 5609-2
            double d1 = 8;
            double l1 = 80;
            double l2 = 6.4;
            double f = 6;
            double dmin = 11;
            double s = 2.38;
            double insertagl = 80 * pi / 180;
            double cutagl = 95 * pi / 180;
            double an = 0 * pi / 180;
            double gamaf = 10 * pi / 180;
            #region
            try
            {
                if (data["an"] != null)
                    an = Convert.ToDouble(data["an"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["s"] != null)
                    s = Convert.ToDouble(data["s"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmm"] != null)
                    d1 = Convert.ToDouble(data["dmm"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["lf"] != null)
                    l1 = Convert.ToDouble(data["lf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["l"] != null)
                    l2 = Convert.ToDouble(data["l"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["wf"] != null)
                    f = Convert.ToDouble(data["wf"]);
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["epsr"] != null)
                    insertagl = Convert.ToDouble(data["epsr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["kapr"] != null)
                    cutagl = Convert.ToDouble(data["kapr"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["dmin"] != null)
                    dmin = Convert.ToDouble(data["dmin"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            try
            {
                if (data["gamf"] != null)
                    gamaf = Convert.ToDouble(data["gamf"]) * pi / 180;
            }
            catch (KeyNotFoundException) { }
            Dictionary<double, double> l2_repsilon = new Dictionary<double, double>() {
                { 6.4,0.4},
                { 9.7,0.8},
                { 12.9,0.8},
                { 16.1,1.2},
                { 19.3,1.2},
            };
            double repsilon = l2_repsilon[l2];
            #endregion
            //倒角
            double chamfer = 0.5;
            //刀柄部长度
            double dtl = d1 * 1.2;
            Vector2 c1 = new Vector2(0, 0);
            Vector2 c2 = new Vector2(c1.X - d1 / 2 + chamfer, c1.Y);
            Vector2 c3 = new Vector2(c1.X - d1 / 2, c1.Y - chamfer);
            Vector2 c4 = new Vector2(c3.X, c3.Y - dtl);
            Vector2 c5 = new Vector2(c4.X + d1, c4.Y);
            Vector2 c6 = new Vector2(c5.X, c3.Y);
            Vector2 c7 = new Vector2(c1.X + d1 / 2 - chamfer, c1.Y);
            LwPolyline dtcontour = Pus.AddPointsToLwPolyLine(c5, c6, c7, c1, c2, c3, c4);
            fun.PolyFill(dxf, dtcontour, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c3, c6);
            dxf.AddEntity(Pus.TwoPointsWaveline(c4, c5, 5, 0.5));
            Vector2 c8 = new Vector2(c4.X, c4.Y - 7);
            Vector2 c12 = new Vector2(c5.X, c8.Y);
            dxf.AddEntity(Pus.TwoPointsWaveline(c8, c12, 5, 0.5));
            Vector2 c9 = new Vector2(c8.X, c8.Y - dtl);
            Vector2 c11 = new Vector2(c12.X, c9.Y);
            Pus.DrawPlineByTwoPoints(dxf, c9, c11);
            LwPolyline arc9_11 = Pus.AddPointsToLwPolyLine(c11, c9);
            arc9_11.Vertexes[0].Bulge = Math.Tan( pi / 20);
            fun.PolyFill(dxf, arc9_11, 0.1, contour);
            Vector2 c10 = new Vector2(c9.X, c9.Y - l2 * 2);
            //f,l1是到刀尖圆弧的距离，f是k点距离中心线的长度，k点位置参考5609-2
            Vector2 k1 = new Vector2(c1.Y + f - repsilon, c1.Y - l1);
            Vector2 kc = fun.Polar(k1, pi / 2, repsilon);
            Vector2 k2 = fun.Polar(kc, pi / 2 - insertagl, repsilon);
            Vector2 k2p = fun.Polar(k2, -insertagl, 1);
            Vector2 i4 = fun.Inters(k1, new Vector2(k1.X + 1, k1.Y), k2, k2p);
            Vector2[] insertcontourpoints = Pus.DiamondPointsV(i4, l2, insertagl, false, cutagl);
            Vector2 i1 = insertcontourpoints[1];
            Vector2 i2 = insertcontourpoints[2];
            Vector2 i3 = insertcontourpoints[3];
            LwPolyline littleangle = Pus.AddPointsToLwPolyLine(fun.Polar(i2, Vector2.Angle(i2, i1), 3), i2, fun.Polar(i2, Vector2.Angle(i2, i3), 3));
            fun.PolyFill(dxf, littleangle, 0.1, contour);
            //insert底部轮廓
            double insertoffset = s * Math.Tan(an);
            Vector2[] buttominsert = Pus.OffsetPoints(insertoffset, insertcontourpoints);
            //为四个角倒圆
            LwPolyline insertcontour = Pus.AddPointsToLwPolyLine(insertcontourpoints);
            insertcontour.IsClosed = true;
            Pus.AglToArc(insertcontour, repsilon);
            fun.PolyFill(dxf, insertcontour, 0.1, contour);
            //shank
            c8 = fun.Inters(c10, c9, i4, i1);
            c7 = new Vector2(i3.X - 2, i3.Y);
            c6 = new Vector2(c5.X, c7.Y + 2);
            LwPolyline pline = Pus.AddPointsToLwPolyLine(insertcontour.Vertexes[2].Position, c8, c9, c10, c11, c1, c3, c4, c5, c6, c7, insertcontour.Vertexes[7].Position);
            fun.PolyFill(dxf, pline, 0.1, contour);
            Pus.DrawPlineByTwoPoints(dxf, c4, c10);
            Pus.DrawPlineByTwoPoints(dxf, c5, c9);
            //曲线
            LwPolyline mc = Pus.AddPointsToLwPolyLine(c9, c5);
            mc.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
            fun.PolyFill(dxf, mc, 0.1, contour);
            //中心线
            fun.drawPlinetype(dxf, new Vector2[] { new Vector2(c1.X, c1.Y + 1), new Vector2(c1.X, c1.Y - l1 - 1) }, 0.15, centre, Linetype.Center);
            //剖切符号
            double texth = 2.5;
            dxf.AddEntity(Pus.SectionSymbol(new Vector2((i3.X + i4.X) / 2, i3.Y - 0.5), new Vector2((i3.X + i4.X) / 2, i1.Y + 0.5), "a", 7, 1, texth));
            //标注
            DimensionStyle dimensionstyle = fun.CreateDimStyle();
            dimensionstyle.ArrowSize = 0.2;
            dimensionstyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionstyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionstyle.TextHeight = 0.5;
            double offset = 7;
            LinearDimension dim_l1 = new LinearDimension(new Line(i4, c11), offset, -90, dimensionstyle);
            fun.dxflinedim(dxf, dim_l1, l1);
            LinearDimension dim_f = new LinearDimension(new Line(i4, new Vector2(c1.X, i3.Y)), offset * 1.5, 180, dimensionstyle);
            fun.dxflinedim(dxf, dim_f, f);
            LinearDimension dim_l2 = new LinearDimension(new Line(i1, i2), offset * 0.5, 180, dimensionstyle);
            fun.dxflinedim(dxf, dim_l2, l2);
            LinearDimension dim_d1 = new LinearDimension(new Line(c10, c4), offset * 0.5, 0, dimensionstyle);
            dim_d1.UserText = "φ" + d1;
            dxf.AddEntity(dim_d1);
            Angular2LineDimension dim_cutagl = new Angular2LineDimension(new Line(i4, i3), new Line(i4, new Vector2(i4.X, i4.Y - 1)), 1, dimensionstyle);
            dim_cutagl.UserText = cutagl * 180 / pi + "°";
            dim_cutagl.SetDimensionLinePosition(new Vector2(i4.X - 3, i4.Y - 3));
            dxf.AddEntity(dim_cutagl);
            //刀尖圆弧
            RadialDimension dim_repsilon = Pus.ReDimension(insertcontour, 1, dimensionstyle);
            dim_repsilon.UserText = "rε=" + repsilon;
            dim_repsilon.SetDimensionLinePosition(new Vector2(i4.X + 1, i4.Y - 1));
            dxf.AddEntity(dim_repsilon);
            //剖视图
            /*
            if (an == 11 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i4.X + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.X, a1.Y + l2 * Math.Sin(insertagl));
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutpoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_p;
                if (an == 11 * pi / 180)
                    inclination_p = 6;
                else if (an == 7 * pi / 180)
                    inclination_p = 0;
                else
                    inclination_p = -6;
                //double inclination_n = -6;
                //double inclination_c = 0;
                Vector2[] p = Pus.ToVertical(absolutpoints[0], inclination_p * pi / 180, absolutpoints);
                //中心线
                Vector2 cendpoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendpoint }, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<hatchboundarypath> boundary = new List<hatchboundarypath>();
                hatchboundarypath pcpath = new hatchboundarypath(pcontour1.explode());
                hatchboundarypath hpath2 = new hatchboundarypath(new list<entityobject> { spline });
                boundary.Add(pcpath);
                boundary.Add(hpath2);
                Hatch hatch1 = new Hatch(hatchpattern.line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(p)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(c)";
                else
                    text = "αn=0°(n)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pcentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionstyle2 = fun.CreateDimStyle();
                dimensionstyle2.ArrowSize = 0.1;
                dimensionstyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionstyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionstyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_p = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].X, p[1].Y - 1)), new line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionstyle);
                    dim_inclination_p.UserText = inclination_p + "°";
                    dxf.AddEntity(dim_inclination_p);
                }
                catch (Exception) { }
                Text ptext = new Text("a-a", new Vector2(cendpoint.X - 4, cendpoint.Y + 1), texth, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 7 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i4.X + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.X, a1.Y + l2 * Math.Sin(insertagl));
                Vector2 a3 = new Vector2(a1.X, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.X - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.X - s, a1.Y + s * Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.X - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutpoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_p;
                if (an == 11 * pi / 180)
                    inclination_p = 6;
                else if (an == 7 * pi / 180)
                    inclination_p = 0;
                else
                    inclination_p = -6;
                //double inclination_n = -6;
                //double inclination_c = 0;
                Vector2[] p = Pus.ToVertical(absolutpoints[0], inclination_p * pi / 180, absolutpoints);
                //中心线
                Vector2 cendpoint = new Vector2(p[1].X, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].X, p[1].Y - 1), cendpoint }, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                List<hatchboundarypath> boundary = new List<hatchboundarypath>();
                hatchboundarypath pcpath = new hatchboundarypath(pcontour1.explode());
                hatchboundarypath hpath2 = new hatchboundarypath(new list<entityobject> { spline });
                boundary.add(pcpath);
                boundary.add(hpath2);
                Hatch hatch1 = new Hatch(hatchpattern.line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(p)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(c)";
                else
                    text = "αn=0°(n)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pcentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionstyle2 = fun.CreateDimStyle();
                dimensionstyle2.ArrowSize = 0.1;
                dimensionstyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionstyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionstyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_p = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].x, p[1].Y - 1)), new line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionstyle);
                    dim_inclination_p.UserText= inclination_p + "°";
                    dxf.AddEntity(dim_inclination_p);
                }
                catch (Exception) { }
                Text ptext = new Text("a-a", new Vector2(cendpoint.x - 4, cendpoint.Y + 1), texth, 0);
                dxf.AddEntity(ptext);
            }
            else if (an == 0 * pi / 180)
            {
                double anv = an;
                Vector2 a1 = new Vector2(i4.x + offset * 3, i4.Y);
                Vector2 a2 = new Vector2(a1.x, a1.Y + l2 * Math.Sin(insertagl));
                Vector2 a3 = new Vector2(a1.x, a2.Y + 4);
                Vector2 a4 = new Vector2(a1.x - (s + 3), a1.Y + (s + 3) * Math.Tan(anv));
                Vector2 a5 = new Vector2(a1.x - s, a1.Y + s * Math.Tan(anv));
                Vector2 a6 = new Vector2(a2.x - s, a2.Y - s * Math.Tan(anv));
                Vector2[] absolutpoints = { a1, a1, a2, a3, a4, a5, a6 };
                double inclination_p;
                if (an == 11 * pi / 180)
                    inclination_p = 6;
                else if (an == 7 * pi / 180)
                    inclination_p = 0;
                else
                    inclination_p = -6;
                //double inclination_n = -6;
                //double inclination_c = 0;
                Vector2[] p = Pus.ToVertical(absolutpoints[0], inclination_p * pi / 180, absolutpoints);
                //中心线
                Vector2 cendpoint = new Vector2(p[1].x, p[1].Y + offset * 2.1);
                fun.drawPlinetype(dxf, new Vector2[] { new Vector2(p[1].x, p[1].Y - 1), cendpoint }, centre, Linetype.Center);
                //样条曲线
                Spline spline = new Spline(Pus.AddpointsToSpline(Pus.Recoil(p[4], p[3])));
                dxf.AddEntity(spline);
                LwPolyline pcontour1 = Pus.AddPointsToLwPolyLine(p[3], p[2], p[6], p[5], p[4]);
                fun.PolyFill(dxf, pcontour1, 0.1, contour);
                LwPolyline pcut = Pus.AddPointsToLwPolyLine(p[1], p[2], p[6], p[5]);
                pcut.IsClosed = true;
                fun.PolyFill(dxf, pcut, 0.1, contour);
                Pus.HatchThePolyline(dxf, pcut, -40, 2);
                //填充1
                list<hatchboundarypath> boundary = new list<hatchboundarypath>();
                hatchboundarypath pcpath = new hatchboundarypath(pcontour1.explode());
                hatchboundarypath hpath2 = new hatchboundarypath(new list<entityobject> { spline });
                boundary.add(pcpath);
                boundary.add(hpath2);
                Hatch hatch1 = new Hatch(hatchpattern.line, boundary, true);
                hatch1.Pattern.Angle = 45;
                hatch1.Pattern.Scale = 4;
                dxf.AddEntity(hatch1);
                string text;
                if (an == 11 * pi / 180)
                    text = "αn=11°(p)";
                else if (an == 7 * pi / 180)
                    text = "αn=7°(c)";
                else
                    text = "αn=0°(n)";
                Text text1 = new Text(text, new Vector2(p[4].X - 8, p[4].Y + 8), 1, 0);
                dxf.AddEntity(text1);
                Line pcentre = new Line(new Vector2(p[1].X, p[1].Y - 1), new Vector2(p[1].X, p[1].Y + offset * 8));
                DimensionStyle dimensionstyle2 = fun.CreateDimStyle();
                dimensionstyle2.ArrowSize = 0.1;
                dimensionstyle2.DimArrow1 = DimensionArrowhead.Dot;
                dimensionstyle2.DimArrow2 = DimensionArrowhead.Dot;
                dimensionstyle2.TextHeight = 0.3;
                try
                {
                    Angular2LineDimension dim_inclination_p = new Angular2LineDimension(new Line(p[1], new Vector2(p[1].x, p[1].Y - 1)), new line(p[1], fun.Polar(p[1], Vector2.Angle(p[3], p[1]), 2)), 8, dimensionstyle);
                    dim_inclination_p.UserText = inclination_p + "°";
                    dxf.AddEntity(dim_inclination_p);
                }
                catch (Exception) { }
                Text ptext = new Text("a-a", new Vector2(cendpoint.x - 4, cendpoint.Y + 1), texth, 0);
                dxf.AddEntity(ptext);
            }
            */
            //x视图
            Vector2 cs = new Vector2(c6.X - offset * 3.5, c6.Y);
            //中心线
            Line vcline = new Line(new Vector2(cs.X, cs.Y + dmin / 2 + 0.5), new Vector2(cs.X, cs.Y - dmin / 2 - 0.5));
            vcline.Layer = centre;
            vcline.Linetype = Linetype.Center;
            dxf.AddEntity(vcline);
            Line hcline = new Line(new Vector2(cs.X + 10, cs.Y), new Vector2(cs.X - 10, cs.Y));
            hcline.Layer = centre;
            hcline.Linetype = Linetype.Center;
            dxf.AddEntity(hcline);
            //
            double tk = 6 * pi / 180;
            Vector2 x1 = new Vector2(cs.X + f / Math.Cos(gamaf), cs.Y);
            Vector2 x2 = new Vector2(x1.X - l2, x1.Y);
            Vector2 x3 = new Vector2(x2.X + s * Math.Tan(tk), x2.Y - s);
            Vector2 x4 = new Vector2(x1.X - s * Math.Tan(tk), x1.Y - s);
            Vector2[] x = Pus.ToVertical(x1, -gamaf, x1, x1, x2, x3, x4);
            x1 = x[1];
            x2 = x[2];
            x3 = x[3];
            x4 = x[4];
            LwPolyline xcontour = Pus.AddPointsToLwPolyLine(x1, x2, x3, x4);
            xcontour.IsClosed = true;
            fun.PolyFill(dxf, xcontour, 0.1, contour);
            Circle c_s = new Circle(cs, d1 / 2);
            Vector2 xx1 = Pus.LineXCir(c_s, x1, x2)[1];
            Vector2 xx2 = Pus.LineXCir(c_s, x1, x2)[0];
            //dxf.AddEntity(new line(xx1, x4));
            double cs_startagl = Vector2.Angle(cs, xx1);
            Arc sarc = new Arc(cs, d1 / 2, cs_startagl * 180 / pi, 270);
            sarc.Layer = contour;
            sarc.Linetype = Linetype.ByLayer;
            dxf.AddEntity(sarc);
            Pus.DrawPlineByTwoPoints(dxf, x2, xx2);
            //cd
            Vector2 cd = new Vector2(x1.X - dmin / 2, cs.Y);
            //中心线
            Line vcline_cd = new Line(new Vector2(cd.X, cd.Y + 3), new Vector2(cd.X, cd.Y - 3));
            vcline_cd.Layer = centre;
            vcline_cd.Linetype = Linetype.Center;
            dxf.AddEntity(vcline_cd);
            //构造线（圆）
            Circle c_d = new Circle(cd, Vector2.Distance(x1, cd));
            c_d.Linetype = Linetype.DashDot;
            dxf.AddEntity(c_d);
            //cx
            double bigger = 2.7;
            Vector2 cx = new Vector2(cs.X, cs.Y + bigger);
            Circle c_x = new Circle(cx, d1 / 2 + bigger);
            Vector2 xx3 = Pus.LineXCir(c_x, x3, x4)[1];
            double cx_endagl = Vector2.Angle(cx, xx3);
            Arc cx_arc = new Arc(cx, c_x.Radius, 270, cx_endagl * 180 / pi);
            cx_arc.Layer = contour;
            dxf.AddEntity(cx_arc);
            double textheigth = 2.5;
            //t1,t2
            Vector2 t1 = fun.Polar(x2, Vector2.Angle(x1, x2), d1 / 4);
            Vector2 t2 = Pus.LineXCir(c_s, t1, new Vector2(t1.X, t1.Y - 1))[0];
            Pus.DrawPlineByTwoPoints(dxf, t1, t2);
            //x
            dxf.AddEntity(Pus.MyArrow(new Vector2(i3.X, i3.Y - offset * 2), -90, 1.9, 5));
            dxf.AddEntity(new Text("x", new Vector2(i3.X - 1, i3.Y - offset * 2 - 5 - 3), textheigth, 0));
            //x-x
            dxf.AddEntity(new Text("x", new Vector2(cs.X, cs.Y + offset * 1.5), textheigth, 0));
            //x标注
            LinearDimension dim_dmin = new LinearDimension(new Line(fun.Polar(x1, pi, dmin), x1), offset * 1.6, 180, dimensionstyle);
            fun.dxflinedim(dxf, dim_dmin, dmin);
            LinearDimension dim_h1 = new LinearDimension(new Line(fun.Polar(cs, 1.5 * pi, d1 / 2), cs), offset * 2, -90, dimensionstyle);
            fun.dxflinedim(dxf, dim_h1, d1 / 2);
            LinearDimension dim_s = new LinearDimension(new Line(x1, x4), offset * 0.5, Vector2.Angle(x1, x4) * 180 / pi, dimensionstyle);
            fun.dxflinedim(dxf, dim_s, s);
            Angular2LineDimension dim_gamaf = new Angular2LineDimension(new Line(x1, fun.Polar(x1, Vector2.Angle(x2, x1), 1)), new Line(x1, new Vector2(x1.X + 1, x1.Y)), 10, dimensionstyle);
            dim_gamaf.UserText = gamaf * 180 / pi + "°";
            dxf.AddEntity(dim_gamaf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
